﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QuanLyNhaHang.Bussiness
{
    class BusNewTable
    {
        DataAccess.DAOrder data = new DataAccess.DAOrder();
        GUI.OrderOption.NewTable f;
        public BusNewTable(GUI.OrderOption.NewTable f2)
        {
            f = f2;
        }

        public void loadCombo()
        {
            this.f.cboKV.DataSource = data.optionNTLoadCbo();
            this.f.cboKV.DisplayMember = "TEN_KHUVUC";
            this.f.cboKV.ValueMember = "TEN_KHUVUC";
        }

        public bool newTable()
        {
            try
            {
                if (checkNewTable())
                {
                    String[] a = { this.f.cboKV.SelectedValue.ToString(), this.f.txtTenBan.Text.Trim() };
                    if (data.optionNTNew(a))
                    {
                        this.f.lblInfo.Text = "Thêm mới thành công";
                        return true;
                    };
                }
            }
            catch (Exception)
            {
                return false;
            }

            return false;
        }

        public bool checkNewTable()
        {
            String[] a = {this.f.cboKV.SelectedValue.ToString(),this.f.txtTenBan.Text.Trim()};

            if (data.optionCheckNewTable(a))
            {
                this.f.lblInfo.Text = "Tên bàn rỗng hoặc đã tồn tại";
                return false;
            }

            return true;
        }
    }
}
